//
//  UIBarButtonItem+Extensions.swift
//  微博
//
//  Created by LoadingMx on 2017/3/18.
//  Copyright © 2017年 LoadingMx. All rights reserved.
//

import Foundation

extension UIBarButtonItem {
    
    /// 创建 UIBarButton
    ///
    /// - Parameters:
    ///   - title: title
    ///   - fontSize: 字体大小, 默认 16
    ///   - target: target
    ///   - action: action
    ///   - isBack: 是否是返回按钮,如果是加上箭头
    convenience init(title: String, fontSize: CGFloat = 16, target: AnyObject?, action: Selector, isBack: Bool = false) {
        let btn: UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        if isBack {
            let imageName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named: imageName), for: .normal)
            btn.setImage(UIImage(named: imageName + "_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        btn.addTarget(target, action: action, for: .touchUpInside)
        // self.init 实例化
        self.init(customView: btn)
    }
}
